﻿function DoOpenBox(IdBox) {
    var hightdocument = $(document).height();
    var widthdocument = $(document).width();
    var hightwindown = $(window).height();
    var widthwindown = $(window).width();
    $("#" + IdBox).css({ "top": +(hightwindown / 2.5) + "px", "left": +(widthwindown / 2) + "px", "display": "block" });
    $("#boxBlockDisplay").css({ "width": +(widthdocument) + "px", "height": +(hightdocument) + "px", "display": "block" });
}

function DoCloseBox(IdBox) {
    $("#" + IdBox).css("display", "none");
    $("#boxBlockDisplay").css("display", "none");
}

function DoCheckError_Json(textStatus) {
    if (textStatus.status === 401) {
        if (confirm("Thời hạn đăng nhập đã hết ! Bạn có muốn đăng nhập lại ?"))
            window.location.href = basePath + "Authentication/Login";

    } else {
        document.getElementById("Message").innerHTML = "Lỗi kết nối! Vui lòng liên hệ admin!";
    }
}

function BuildHeaderTable(arrTieuDe) {
    var str = "";
    str += "<thead><tr>";
    if (arrTieuDe != null && arrTieuDe.length > 0)
        for (var i = 0; i < arrTieuDe.length; i++) {
            str += "<th nowrap='nowrap'>" + arrTieuDe[i] + "</th>";
        }
    str += "</tr></thead>";
    return str;
}

function BuildFooterTable(SoCot, TotalItem, TotalPage, PageNumber, eventOnclick) {
    var str = "";
    str += "<tfoot><tr>";
    str += "<td class=\"first\" style=\"background: #DDDDDD\"></td>";
    str += "<td class=\"last\" colspan=\"" + SoCot + "\" align=\"right\" style=\"background: #DDDDDD; padding-right: 10px\">";
    if (TotalPage > 0) {
        str += "<div><div>";
        if (PageNumber == 1) {
            str += "<input type=\"button\" class=\"btn btn-primary\" value=\"Đầu\" disabled=\"disabled\" />&nbsp;";
            str += "<input type=\"button\" class=\"btn btn-primary\" value=\"Lùi\" disabled=\"disabled\" />&nbsp;";
        }
        else {
            str += "<input type=\"button\" class=\"btn btn-primary\" value=\"Đầu\" onclick='javascript:" + eventOnclick + "(1)' />&nbsp;";
            str += "<input type=\"button\" class=\"btn btn-primary\" value=\"Lùi\" onclick='javascript:" + eventOnclick + "(" + (PageNumber - 1) + ")' />&nbsp;";
        }
        var a = 3;
        for (var i = PageNumber - a; i <= PageNumber + a; i++) {
            if (i == PageNumber)
                str += "[" + i + "/" + TotalPage + "]&nbsp;";
            else if (i > 0 && i <= TotalPage) {
                str += "<input type=\"button\" class=\"btn\" value=\"" + i + "\" onclick='javascript:" + eventOnclick + "(" + (i) + ")' />&nbsp;";
            }
        }
        if (PageNumber == TotalPage) {
            str += "<input type=\"button\" class=\"btn btn-primary\" value=\"Tiếp\" disabled=\"disabled\" />&nbsp;";
            str += "<input type=\"button\" class=\"btn btn-primary\" value=\"Cuối\" disabled=\"disabled\" />&nbsp;";
        }
        else {
            str += "<input type=\"button\" class=\"btn btn-primary\" value=\"Tiếp\" onclick='javascript:" + eventOnclick + "(" + (PageNumber + 1) + ")' />&nbsp;";
            str += "<input type=\"button\" class=\"btn btn-primary\" value=\"Cuối\" onclick='javascript:" + eventOnclick + "(" + (TotalPage) + ")' />&nbsp;";
        }
        str += "</div></div>";
    }
    str += "</td></tr></tfoot>";
    return str;
}

function BuildFirstTable() {
    return "<table class='table table-bordered table-condensed'>";
}

function BuildLastTable() {
    return "</table>";
}

